<template>
  <view class=" boxs whe_maxv_view" style="padding: 0 10px 20px">
    <view @click="addDetail(item)" class="mag_t-10 bor_10 pad_10 boxs xyy wh_f"
          v-for="(item,index) in listShop" :key="index">
      <view style="width: 100px">
        <view class="img_zfx">
          <image class="bor_10" :src="item.shop_good.image[0]" />
        </view>
      </view>
      <view class="flex_1 fz_12">
        <view class="wh_9 jz">
          <view class="fz_16 em" style="color: #383838">{{ item.shop_good.name }}</view>
          <view class="split_2 pad_5_0">
            <view>月售 {{ item.shop_good.sales }}+</view>
            <view>库存 {{ item.shop_good.stock }}</view>
          </view>
          <view class="fz_10 wz_white">
            <text class="wz_hui">规格 {{ item.shop_good.specs }} </text>
            <text class="mag_l_5" style="border-radius: 3px;padding: 2px 5px;
                    background-color: #d5f0dd;color: #3a9e5f">{{ item.shop_good.category_pstr }}</text>
          </view>
          <view class="split_2" style="padding: 5px 0">
            <view>
              <view style="color:#e63946;">
                <text>￥</text>
                <text class="fz_16 em">{{ parseInt(item.shop_good.price) }}</text>
                <text>.{{ String(item.shop_good.price).split('.')[1] }}</text>
              </view>
            </view>
            <view class="wh_f_r">
              <view></view>
              <view @click="isSc(item)" class="u-nav-slot wz_rigdq">
                <img  class="icon_wh centerdq"
                     src="../../static/icon/shoucang.png" alt="">
                <text class="centerdq" style="color: #ffc107">取消收藏</text>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <view v-if="listShop.length<1" class="jz_flex" style="height: 60%">
      <view class="wz_jz">
        <image style="width: 200px;height: 130px" src="https://xdjzapi.towngo.cn/uploads/images/wx/202507/08/xcx_1751945016_KEXbwbZngN.png"></image>
        <view class="mag_t-20">快去收藏商品吧!</view>
      </view>
    </view>
    <up-toast ref="uToastRef"></up-toast>

  </view>
</template>
<script>
import {collectShopGood, shopGoodCollects} from "../../Api/shop";

export default {
  name: "index",
  data(){
    return{
      listShop:[]
    }
  },
  onShow(){
    shopGoodCollects().then(res=>{
      console.log('收藏列表',res.data.data)
      this.listShop = res.data.data
    })
  },
  methods:{
    //消息提示
    showToast(msg, type = "default") {
      uni.showToast({
        title: msg,
        icon: "none", // 图标类型，可选值：success, none
        duration: 2000 // 显示时间，单位毫秒
      });
    },
    isSc(e){
      collectShopGood({
        goods_id:e.shop_goods_id
      }).then(res=>{
        this.showToast('取消收藏成功!')
        this.getList()
      })
    },
    getList(){
      shopGoodCollects().then(res=>{
        this.listShop = res.data.data
      })
    },
    addDetail(e){
      console.log(e)
      const params = { id:e.shop_good.id}; // 待传递的参数
      uni.navigateTo({
        url: `/shophome/shopDetail/index?id=${params.id}`
      });
    },
  }
}
</script>
<style scoped lang="scss">

</style>
